from 数据库操作.CreateMysqlCon import CreateMysqlCon

class UpdatePassword:

    def __init__(self):
        self.con = CreateMysqlCon().get_con()
        if not self.con:
            raise ConnectionError("数据库连接失败，请检查配置或网络")
        self.cursor = self.con.cursor()

    def update_password(self, username, password):
        sql = "UPDATE user_data SET password = %s WHERE username = %s;"
        result = self.cursor.execute(sql, (password, username))
        if result > 0:
            return True
        else:
            return False